package codeRandomThoughts.Test300最长递增子序列;

import java.util.Arrays;

public class Solution2 {
    public int lengthOfLIS(int[] nums) {
        int len = nums.length;
        //dp[i]:以nums[i]为结尾的最长严格递增子序列的长度
        int[] dp = new int[len];

        //初始化
        Arrays.fill(dp, 1);

        //开始递推
        for (int i = 1; i < len; i++) {
            for (int j = 0; j < i; j++) {
                //和之前的子序列一一比较
                if (nums[i] > nums[j]) {
                    dp[i] = Math.max(dp[j] + 1, dp[i]);
                }
            }
        }

        int maxLen = 0;
        for (int i : dp) {
            maxLen = Math.max(maxLen, i);
        }

        return maxLen;
    }
}
